﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.PopulationUI {
    import flash.utils.*;
    import Display.DialogUI.*;
    import Classes.*;
    import Classes.util.*;
    import Display.*;
    import Classes.inventory.*;
    import Display.aswingui.*;

    public class ResourceExplanationDialog extends GenericDialog {

        public static const TYPE_NOT_ENOUGH_GOODS:String = "ResourceInfoGoods";
        public static const TYPE_NOT_ENOUGH_HAPPINESS_RESIDENCE:String = "ResourceInfoPop_Residence";
        public static const TYPE_NOT_ENOUGH_HAPPINESS_BUSINESS:String = "ResourceInfoPop_Business";

        protected static var m_shownAlready:Dictionary = new Dictionary();
        private static var m_forceShow:Boolean = false;

        protected var m_explanationType:String;
        protected var m_params:Object;

        public function ResourceExplanationDialog(_arg1:String, _arg2:InstantiationSentinel, _arg3:Function, _arg4:Object){
            this.m_explanationType = _arg1;
            this.m_params = _arg4;
            super("", "", GenericDialogView.TYPE_OK, _arg3, _arg1);
        }
        public static function show(_arg1:String, _arg2:Boolean=false, _arg3:Function=null, _arg4:Object=null):void{
            var _local5:ResourceExplanationDialog;
            if ((((m_shownAlready[_arg1] == true)) && ((_arg2 == false)))){
                return;
            };
            if (((IdleDialogManager.ShowingIdleDialog) && ((_arg2 == false)))){
                return;
            };
            m_forceShow = _arg2;
            if (_arg1 == TYPE_NOT_ENOUGH_GOODS){
                UI.displayOutOfGoodsDialog();
                m_shownAlready[_arg1] = true;
            } else {
                _local5 = new ResourceExplanationDialog(_arg1, new InstantiationSentinel(), _arg3, _arg4);
                UI.displayPopup(_local5);
            };
        }

        override protected function loadAssets():void{
            Global.delayedAssets.get(DelayedAssetLoader.POPULATION_ASSETS, makeAssets);
        }
        override protected function createAssetDict():Dictionary{
            var _local1:Dictionary = new Dictionary();
            _local1["bg"] = m_comObject.info_dialog_with_title;
            _local1["info"] = this.getInfoAsset(this.m_explanationType);
            return (_local1);
        }
        protected function getInfoAsset(_arg1:String):Class{
            switch (_arg1){
                case TYPE_NOT_ENOUGH_GOODS:
                    return (m_comObject.info_food_flow);
                case TYPE_NOT_ENOUGH_HAPPINESS_RESIDENCE:
                case TYPE_NOT_ENOUGH_HAPPINESS_BUSINESS:
                default:
                    return (m_comObject.info_municipal_flow);
            };
        }
        override protected function createDialogView(_arg1:Dictionary):GenericDialogView{
            if (m_forceShow){
                m_forceShow = false;
            };
            var _local2:Object = this.getDialogText(this.m_explanationType);
            return (new ResourceExplanationDialogView(_arg1, m_title, _local2.line1, _local2.line2, _local2.legend, m_callback));
        }
        protected function getDialogText(_arg1:String):Object{
            this.addFormattingParams(_arg1, this.m_params);
            var _local2:Object = {
                line1:"",
                line2:"",
                legend:""
            };
            _local2.line1 = ZLoc.t("Dialogs", (_arg1 + "_line1"), this.m_params);
            if (this.showLine1a(_arg1)){
                _local2.line1 = ZLoc.t("Dialogs", (_arg1 + "_line1a"), this.m_params);
            };
            _local2.line2 = ZLoc.t("Dialogs", (_arg1 + "_line2"), this.m_params);
            _local2.legend = ZLoc.t("Dialogs", (_arg1 + "_legend"), this.m_params);
            return (_local2);
        }
        protected function showLine1a(_arg1:String):Boolean{
            switch (_arg1){
                case TYPE_NOT_ENOUGH_GOODS:
                    return ((Global.player.commodities.getCount(Commodities.GOODS_COMMODITY) > 0));
                default:
                    return (false);
            };
        }
        protected function addFormattingParams(_arg1:String, _arg2:Object):void{
            var _local3:String;
            var _local4:String;
            var _local5:String;
            var _local6:String;
            var _local7:String;
            if (_arg2){
                _local3 = EmbeddedArt.DEFAULT_FONT_NAME_BOLD;
                _local4 = ZLoc.t("Dialogs", (_arg1 + "_bold0"));
                _local5 = ZLoc.t("Dialogs", (_arg1 + "_bold1"));
                _local6 = ZLoc.t("Dialogs", (_arg1 + "_bold2"));
                _local7 = ZLoc.t("Dialogs", (_arg1 + "_bold3"));
                _arg2.bold0 = ASwingHelper.applyFont((_local4) ? _local4 : "", _local3);
                _arg2.bold1 = ASwingHelper.applyFont((_local5) ? _local5 : "", _local3);
                _arg2.bold2 = ASwingHelper.applyFont((_local6) ? _local6 : "", _local3);
                _arg2.bold3 = ASwingHelper.applyFont((_local7) ? _local7 : "", _local3);
            };
        }

    }
}//package Display.PopulationUI 

class InstantiationSentinel {

    public function InstantiationSentinel(){
    }
}
